package org.example.Day4;

import java.util.Objects;

public class Student implements Comparable<Student>{
    //comparator比较器
    private String name;

    private int age;
    private double height;
    public Student(){

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Double.compare(height, student.height) == 0 && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, height);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(String name, double height, int age){
        this.name =name;
        this.height = height;
        this.age = age;
    }
    @Override
    public int compareTo(Student o){
        // 约定1：认为左边对象 ⼤于 右边对象 请您返回正整数
        // 约定2：认为左边对象 ⼩于 右边对象 请您返回负整数
        // 约定3：认为左边对象 等于 右边对象 请您⼀定返回0
        return this.age - o.age;//按年龄升序排列
    }

    @Override
    public String toString(){
        return "Student{"+"name='"+ name +'\''+",age="+age+'\''+",height="+height+'}';
    }

}
